package com.ruoyi.trip.service.impl;

import java.util.List;

import com.ruoyi.city.domain.City;
import com.ruoyi.city.mapper.CityMapper;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.outuser.domain.OutUser;
import com.ruoyi.outuser.mapper.OutUserMapper;
import com.ruoyi.place.mapper.PlaceMapper;
import com.ruoyi.provincial.mapper.ProvincialMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.PortResolverImpl;
import org.springframework.stereotype.Service;
import com.ruoyi.trip.mapper.TripMapper;
import com.ruoyi.trip.domain.Trip;
import com.ruoyi.trip.service.ITripService;

/**
 * 行程管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-07-17
 */
@Service
public class TripServiceImpl implements ITripService 
{
    private static final Logger log = LoggerFactory.getLogger(TripServiceImpl.class);
    @Autowired
    private TripMapper tripMapper;
    @Autowired
    private PlaceMapper placeMapper;
    /**
     * 查询行程管理
     * 
     * @param id 行程管理主键
     * @return 行程管理
     */
    @Override
    public Trip selectTripById(Long id)
    {
        return tripMapper.selectTripById(id);
    }

    /**
     * 查询行程管理列表
     * 
     * @param trip 行程管理
     * @return 行程管理
     */
    @Override
    public List<Trip> selectTripList(Trip trip)
    {
        return tripMapper.selectTripList(trip);
    }

    /**
     * 新增行程管理
     * 
     * @param trip 行程管理
     * @return 结果
     */
    @Autowired
    ProvincialMapper provincialMapper;
    @Autowired
    CityMapper cityMapper;
    @Autowired
    SysUserMapper sysUserMapper;
    @Override
    public int insertTrip(Trip trip)
    {

//        补充基地名
        trip.setName(placeMapper.selectPlaceById(trip.getPid()).getName());
        trip.setCreateTime(DateUtils.getNowDate());
        trip.setCountNum(0L);
        String name = SecurityContextHolder.getContext().getAuthentication().getName();
        trip.setUsername(name);
        SysUser u=new SysUser();
        u.setUserName(name);
        List<SysUser> SysUser = sysUserMapper.selectUserList(u);
        trip.setPhoneNumber(SysUser.get(0).getPhonenumber());
        return tripMapper.insertTrip(trip);
    }

    /**
     * 修改行程管理
     * 
     * @param trip 行程管理
     * @return 结果
     */
    @Override
    public int updateTrip(Trip trip)
    {

        //        补充基地名
        trip.setName(placeMapper.selectPlaceById(trip.getPid()).getName());
        return tripMapper.updateTrip(trip);
    }

    /**
     * 批量删除行程管理
     * 
     * @param ids 需要删除的行程管理主键
     * @return 结果
     */
    @Override
    public int deleteTripByIds(Long[] ids)
    {
        return tripMapper.deleteTripByIds(ids);
    }

    /**
     * 删除行程管理信息
     * 
     * @param id 行程管理主键
     * @return 结果
     */
    @Override
    public int deleteTripById(Long id)
    {
        return tripMapper.deleteTripById(id);
    }
}
